<template>
  <div>
    <h1>填写出货申请</h1>
    <el-form ref="form" v-loading="loading" :model="entity" :rules="rules" label-width="200px">
      <el-form-item label="ID" prop="id" hidden>
        <el-input v-model="entity.id" disabled></el-input>
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input v-model="entity.name"></el-input>
      </el-form-item>
      <el-form-item label="类别" prop="categoryId">
        <category-selector v-model="entity.categoryId"></category-selector>
      </el-form-item>
      <el-form-item label="品级" prop="gradeId">
        <grade-selector v-model="entity.gradeId"></grade-selector>
      </el-form-item>
      <el-form-item label="可供量（吨）" prop="weight">
        <el-input type="number" v-model="entity.weight"></el-input>
      </el-form-item>
      <el-form-item label="单价（每吨/元）" prop="price">
        <el-input type="number" v-model="entity.price"></el-input>
      </el-form-item>
      <el-form-item label="地区" prop="areaId">
        <area-selector v-model="entity.areaId"></area-selector>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSaveAndGo">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import EntityAPI from '@/api/business/good';
import { EditMethods } from '@/utils/crud';
import CategorySelector from '../../business/components/CategorySelector';
import GradeSelector from '../../business/components/GradeSelector';
import AreaSelector from '../../business/components/AreaSelector';

export default {
    components: {
        GradeSelector,
        CategorySelector,
        AreaSelector
    },
    props: {
        id: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            loading: 0,
            entity: {
                id: null,
                name: null
            },
            rules: {
                name: {
                    required: true, trigger: 'blur'
                }
            }
        };
    },
    computed: {
        ...mapGetters([
            'dictionary'
        ])
    },
    created() {
        this.init();
    },
    methods: Object.assign(EditMethods(EntityAPI), {
        newEntity() {
            return {
                name: '',
                categoryId: '',
                teaSeedBaseId: '',
                gradeId: '',
                storehouseId: '',
                companyId: '',
                packageNumber: 0,
                weight: 0,
                price: 0,
                status: 1,
                type: 1
            };
        },
        handleSaveAndGo() {
            this.handleSave(() => {
                this.$router.replace('/u/user/sell-list');
            });
        }
    })
};
</script>

<style lang="scss">
</style>
